package day15.edu;
// Created: 15/09/2025, ChangJiang Ru

public class PrintNumberTest {
    public static void main(String[] args)
    {
    PrintNumber p = new PrintNumber();

    Thread t1 = new Thread(p, "Thread1");
    Thread t2 = new Thread(p, "Thread2");

    t1.start();
    t2.start();
    }



}

class PrintNumber implements Runnable
{
    private int number = 1;
    Object obj = new Object();

    @Override
    public void run()
    {
        while(true)
        {
            synchronized (obj) {

                obj.notify();

                /*
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                 */

                if (number <= 100) {
                    System.out.println(Thread.currentThread().getName() + ": " + number);
                    number++;
                } else
                    break;

                try {
                    obj.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}